<template>
  <div>
    <el-container class="home_box">
      <!--页面头部-->
      <el-header>
        <div>
          <img src="../assets/logo.png" />
          <span>某某公司电商后台管理系统</span>
        </div>
        <el-button type="info" plain @click="logout">系统退出</el-button>
      </el-header>
      <!--主体区域-->
      <el-container>
        <!--侧边栏-->
        <el-aside :width="isCollapse?'64px':'200px'">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <el-menu
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#409eff"
            unique-opend
            :collapse="isCollapse"
            :collapse-transition="false"
            router
          >
            <el-submenu :index="item.path+''"  v-for="item in menulist" :key="item.id">
              <template slot="title">
                <i :class="iconsObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级菜单 -->
              <el-menu-item :index="subItem.path+''" v-for="subItem in item.children" :key="subItem.id">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!--右侧内容区-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data(){
    return {
      // 侧边栏菜单数据
      menulist:[],
      iconsObj:{
        '125': 'el-icon-s-custom',
        '103': 'el-icon-setting',
        '101': 'el-icon-goods',
        '102': 'el-icon-tickets',
        '145': 'el-icon-s-data',
      },
      isCollapse:false
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    logout() {
      // 销毁本地token
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    //获取菜单列表
    async getMenuList(){
      //get menus
      const {data:res} = await this.$http.get('menus')
      if(res.meta.status !== 200) return this.$message.error('获取菜单列表失败')
      this.menulist = res.data
    },
    toggleCollapse(){
      this.isCollapse = !this.isCollapse
    }
  }
};
</script>
<style lang="less" scoped>
.home_box {
  height: 100%;
}
.el-header {
  background-color: #000;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  color: #ffffff;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
    font-size: 20px;
    span {
      margin-left: 20px;
    }
    img {
      width: 60px;
    }
  }
}
.el-aside {
  background-color: #fff;
  .el-menu{
    border-right: none;
  }
}
.toggle-button{
  background-color: #4a5064;
  color: #fff;
  text-align: center;
  font-size: 10px;
  cursor: pointer;
  line-height: 24px;
  letter-spacing: normal;
}
.el-main {
  background-color: #fff;
}
</style>
